﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Module_Debug.Visionox_Gamma
{
    public partial class NT37710_Gamma : Form
    {
        CaSDK CaSDKObj = new CaSDK();
        CRC16 CRCData = new CRC16();
        Gamma_Addr GAMMAs = new Gamma_Addr();

        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke 

        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过

        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        private double lum_off, x_off, y_off;
        private int index = 0;
        private int flag1 = 1; //lum
        private int flag2 = 1; //x
        private int flag3 = 1; //y
        private byte[] Send_buf = new byte[1];
        private byte[] Rec_tmp = new byte[1];
        public byte RM010_0XFE_XX = 0;
        private static bool Gamma_adjust_timeout_flag = false;
        private int adjust_Rnum = 0;
        private int adjust_Gnum = 0;
        private int adjust_Bnum = 0;
        public int adjust_l = 0;
        public int adjust_x = 0;
        public int adjust_y = 0;
        private int step_l = 1;
        //private int step_m = 5;
        private int step_h = 12;

        //监听NT37710挂载
        frmMain frmHelp = null;
        public NT37710_Gamma(frmMain NT37710)
        {
            frmHelp = NT37710;
            InitializeComponent();
            frmHelp.T20.Interval = 200; //采样周期设定
            frmHelp.T20.Tick += new EventHandler(NT37710_auto_gamma);
            Thread.Sleep(5);
            frmHelp.Child_window_hide_already = true;
            frmHelp.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体      
        }  //publi
        //NT37710 监听卸载
        private void NT37710_Gamma_FormClosed(object sender, FormClosedEventArgs e)
        {
            //frmHelp.comPort.Close()
            Thread.Sleep(5);
            frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(NT37710_DataReceived);
            Thread.Sleep(5);
            frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
            Thread.Sleep(5);
            //frmHelp.comPort.Open();

            frmHelp.T20.Tick -= new EventHandler(NT37710_auto_gamma);
            Thread.Sleep(5);
            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "NT37710_Gamma_FormClosed！\r\n";
            frmHelp.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frmHelp.Child_window_hide_already = false;
            frmHelp.IC_comboBox.Enabled = true;
        }

        private void NT37710_Gamma_VisibleChanged(object sender, EventArgs e)
        {
            if (frmHelp.Child_window_hide_already == false) //子窗体已开启标识
            {
                //frmHelp.comPort.Close()
                Thread.Sleep(5);
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(NT37710_DataReceived);
                Thread.Sleep(5);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                Thread.Sleep(5);
                //frmHelp.comPort.Open();
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "NT37710_Gamma_FormHide！\r\n";
                frmHelp.Child_window_hide_already = true; //子窗体已隐藏标识
            }
            else
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                Thread.Sleep(5);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(NT37710_DataReceived);
                Thread.Sleep(5);
                frmHelp.T20.Tick += new EventHandler(NT37710_auto_gamma);
                Thread.Sleep(5);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "NT37710_Gamma_FormOpened！\r\n";
                frmHelp.Child_window_hide_already = false; //子窗体已开启标识
            }
        }


        //串口接收
        private void NT37710_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            if (IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = frmHelp.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                frmHelp.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    // 0x2A: NT37710的Gamma读写、寄存器读写、OTP读写    设置  返回
                    if (buffer[0] == 0x2A && Setting.TempRecord.cmdLen > 0)
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }

                        }
                    }
                    else
                    {
                        buffer.RemoveRange(0, buffer.Count);
                    }
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        frmHelp.T1.Enabled = false; //停止超时计数
                        if (Rec_tmp[0] == 0x2A) //NT37710
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写寄存器\tOK！\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        if (Setting.TempRecord.NT37710CmdType == 0x02)  //register read
                                        {
                                            string tmp = "";
                                            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                            {
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                            }
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                            NT37710_txtRegData.Text = tmp;
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;

                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                        {
                                            if (Convert.ToByte(Rec_tmp[3] & 0x0f) == 0x00)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t写 OK！\r\n";
                                            else if (Convert.ToByte(Rec_tmp[3] & 0x0f) == 0x01)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t写 OK！\r\n";
                                            else if (Convert.ToByte(Rec_tmp[3] & 0x0f) == 0x02)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t写 OK！\r\n";
                                            else if (Convert.ToByte(Rec_tmp[3] & 0x0f) == 0x03)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红绿蓝 Gamma数据\t写 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x0A:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写OTP\t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写OTP\t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x09:
                                    {
                                        if (Setting.TempRecord.NT37710CmdType == 0x03)
                                        {
                                            NT37710_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            NT37710_R1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            NT37710_R3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            NT37710_R5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            NT37710_R7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            NT37710_R9.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            NT37710_R11.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            NT37710_R13.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            NT37710_R15.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            NT37710_R17.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            NT37710_R19.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            NT37710_R23.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            NT37710_R31.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            NT37710_R47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            NT37710_R63.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            NT37710_R79.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            NT37710_R95.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            NT37710_R111.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            NT37710_R127.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            NT37710_R159.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            NT37710_R191.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            NT37710_R223.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            NT37710_R255.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.NT37710CmdType == 0x04)
                                        {
                                            NT37710_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            NT37710_G1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            NT37710_G3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            NT37710_G5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            NT37710_G7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            NT37710_G9.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            NT37710_G11.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            NT37710_G13.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            NT37710_G15.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            NT37710_G17.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            NT37710_G19.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            NT37710_G23.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            NT37710_G31.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            NT37710_G47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            NT37710_G63.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            NT37710_G79.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            NT37710_G95.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            NT37710_G111.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            NT37710_G127.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            NT37710_G159.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            NT37710_G191.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            NT37710_G223.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            NT37710_G255.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.NT37710CmdType == 0x05)
                                        {
                                            NT37710_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            NT37710_B1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            NT37710_B3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            NT37710_B5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            NT37710_B7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            NT37710_B9.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            NT37710_B11.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            NT37710_B13.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            NT37710_B15.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            NT37710_B17.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            NT37710_B19.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            NT37710_B23.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            NT37710_B31.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            NT37710_B47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            NT37710_B63.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            NT37710_B79.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            NT37710_B95.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            NT37710_B111.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            NT37710_B127.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            NT37710_B159.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            NT37710_B191.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            NT37710_B223.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            NT37710_B255.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                default: break;
                            }
                        }
                        frmHelp.textBox1.SelectionStart = this.frmHelp.textBox1.Text.Length;
                        frmHelp.textBox1.ScrollToCaret();//滚动到光标处
                        if (frmHelp.textBox1.Lines.Length > 50) frmHelp.textBox1.Text = null;
                    }));
                }
            }
            finally
            {
                Listening = false;
            }
        }
        //Gamma保存
        private void NT37710_SaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存Gamma文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    str = str + "R0," + NT37710_R0.Text + "," + "G0," + NT37710_G0.Text + "," + "B0," + NT37710_B0.Text + "\r\n";
                    str = str + "R1," + NT37710_R1.Text + "," + "G1," + NT37710_G1.Text + "," + "B1," + NT37710_B1.Text + "\r\n";
                    str = str + "R3," + NT37710_R3.Text + "," + "G3," + NT37710_G3.Text + "," + "B3," + NT37710_B3.Text + "\r\n";
                    str = str + "R5," + NT37710_R5.Text + "," + "G5," + NT37710_G5.Text + "," + "B5," + NT37710_B5.Text + "\r\n";
                    str = str + "R7," + NT37710_R7.Text + "," + "G7," + NT37710_G7.Text + "," + "B7," + NT37710_B7.Text + "\r\n";
                    str = str + "R9," + NT37710_R9.Text + "," + "G9," + NT37710_G9.Text + "," + "B9," + NT37710_B9.Text + "\r\n";
                    str = str + "R11," + NT37710_R11.Text + "," + "G11," + NT37710_G11.Text + "," + "B11," + NT37710_B11.Text + "\r\n";
                    str = str + "R13," + NT37710_R13.Text + "," + "G13," + NT37710_G13.Text + "," + "B13," + NT37710_B13.Text + "\r\n";
                    str = str + "R15," + NT37710_R15.Text + "," + "G15," + NT37710_G15.Text + "," + "B15," + NT37710_B15.Text + "\r\n";
                    str = str + "R17," + NT37710_R17.Text + "," + "G17," + NT37710_G17.Text + "," + "B17," + NT37710_B17.Text + "\r\n";
                    str = str + "R19," + NT37710_R19.Text + "," + "G19," + NT37710_G19.Text + "," + "B19," + NT37710_B19.Text + "\r\n";
                    str = str + "R23," + NT37710_R23.Text + "," + "G23," + NT37710_G23.Text + "," + "B23," + NT37710_B23.Text + "\r\n";
                    str = str + "R31," + NT37710_R31.Text + "," + "G31," + NT37710_G31.Text + "," + "B31," + NT37710_B31.Text + "\r\n";
                    str = str + "R47," + NT37710_R47.Text + "," + "G47," + NT37710_G47.Text + "," + "B47," + NT37710_B47.Text + "\r\n";
                    str = str + "R63," + NT37710_R63.Text + "," + "G63," + NT37710_G63.Text + "," + "B63," + NT37710_B63.Text + "\r\n";
                    str = str + "R79," + NT37710_R79.Text + "," + "G79," + NT37710_G79.Text + "," + "B79," + NT37710_B79.Text + "\r\n";
                    str = str + "R95," + NT37710_R95.Text + "," + "G95," + NT37710_G95.Text + "," + "B95," + NT37710_B95.Text + "\r\n";
                    str = str + "R111," + NT37710_R111.Text + "," + "G111," + NT37710_G111.Text + "," + "B111," + NT37710_B111.Text + "\r\n";
                    str = str + "R127," + NT37710_R127.Text + "," + "G127," + NT37710_G127.Text + "," + "B127," + NT37710_B127.Text + "\r\n";
                    str = str + "R159," + NT37710_R159.Text + "," + "G159," + NT37710_G159.Text + "," + "B159," + NT37710_B159.Text + "\r\n";
                    str = str + "R191," + NT37710_R191.Text + "," + "G191," + NT37710_G191.Text + "," + "B191," + NT37710_B191.Text + "\r\n";
                    str = str + "R223," + NT37710_R223.Text + "," + "G223," + NT37710_G223.Text + "," + "B223," + NT37710_B223.Text + "\r\n";
                    str = str + "R255," + NT37710_R255.Text + "," + "G255," + NT37710_G255.Text + "," + "B255," + NT37710_B255.Text + "\r\n";
                    sw.WriteLine(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        } //
        //Gamma载入
        private void NT37710_LoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
                string[] arrtmp = strtmp.Split(new Char[] { ',' });
                NT37710_R0.Text = arrtmp[1].ToString(); NT37710_G0.Text = arrtmp[3].ToString(); NT37710_B0.Text = arrtmp[5].ToString();
                NT37710_R1.Text = arrtmp[7].ToString(); NT37710_G1.Text = arrtmp[9].ToString(); NT37710_B1.Text = arrtmp[11].ToString();
                NT37710_R3.Text = arrtmp[13].ToString(); NT37710_G3.Text = arrtmp[15].ToString(); NT37710_B3.Text = arrtmp[17].ToString();
                NT37710_R5.Text = arrtmp[19].ToString(); NT37710_G5.Text = arrtmp[21].ToString(); NT37710_B5.Text = arrtmp[23].ToString();
                NT37710_R7.Text = arrtmp[25].ToString(); NT37710_G7.Text = arrtmp[27].ToString(); NT37710_B7.Text = arrtmp[29].ToString();
                NT37710_R9.Text = arrtmp[31].ToString(); NT37710_G9.Text = arrtmp[33].ToString(); NT37710_B9.Text = arrtmp[35].ToString();
                NT37710_R11.Text = arrtmp[37].ToString(); NT37710_G11.Text = arrtmp[39].ToString(); NT37710_B11.Text = arrtmp[41].ToString();
                NT37710_R13.Text = arrtmp[43].ToString(); NT37710_G13.Text = arrtmp[45].ToString(); NT37710_B13.Text = arrtmp[47].ToString();
                NT37710_R15.Text = arrtmp[49].ToString(); NT37710_G15.Text = arrtmp[51].ToString(); NT37710_B15.Text = arrtmp[53].ToString();
                NT37710_R17.Text = arrtmp[55].ToString(); NT37710_G17.Text = arrtmp[57].ToString(); NT37710_B17.Text = arrtmp[59].ToString();
                NT37710_R19.Text = arrtmp[61].ToString(); NT37710_G19.Text = arrtmp[63].ToString(); NT37710_B19.Text = arrtmp[65].ToString();
                NT37710_R23.Text = arrtmp[67].ToString(); NT37710_G23.Text = arrtmp[69].ToString(); NT37710_B23.Text = arrtmp[71].ToString();
                NT37710_R31.Text = arrtmp[73].ToString(); NT37710_G31.Text = arrtmp[75].ToString(); NT37710_B31.Text = arrtmp[77].ToString();
                NT37710_R47.Text = arrtmp[79].ToString(); NT37710_G47.Text = arrtmp[81].ToString(); NT37710_B47.Text = arrtmp[83].ToString();
                NT37710_R63.Text = arrtmp[85].ToString(); NT37710_G63.Text = arrtmp[87].ToString(); NT37710_B63.Text = arrtmp[89].ToString();
                NT37710_R79.Text = arrtmp[91].ToString(); NT37710_G79.Text = arrtmp[93].ToString(); NT37710_B79.Text = arrtmp[95].ToString();
                NT37710_R95.Text = arrtmp[97].ToString(); NT37710_G95.Text = arrtmp[99].ToString(); NT37710_B95.Text = arrtmp[101].ToString();
                NT37710_R111.Text = arrtmp[103].ToString(); NT37710_G111.Text = arrtmp[105].ToString(); NT37710_B111.Text = arrtmp[107].ToString();
                NT37710_R127.Text = arrtmp[109].ToString(); NT37710_G127.Text = arrtmp[111].ToString(); NT37710_B127.Text = arrtmp[113].ToString();
                NT37710_R159.Text = arrtmp[115].ToString(); NT37710_G159.Text = arrtmp[117].ToString(); NT37710_B159.Text = arrtmp[119].ToString();
                NT37710_R191.Text = arrtmp[121].ToString(); NT37710_G191.Text = arrtmp[123].ToString(); NT37710_B191.Text = arrtmp[125].ToString();
                NT37710_R223.Text = arrtmp[127].ToString(); NT37710_G223.Text = arrtmp[129].ToString(); NT37710_B223.Text = arrtmp[131].ToString();
                NT37710_R255.Text = arrtmp[133].ToString(); NT37710_G255.Text = arrtmp[135].ToString(); NT37710_B255.Text = arrtmp[137].ToString();
            }
        }

        //------------------------------------------NT37710_START-----------------------------------------
        private void NT37710_trackBar_Scroll(object sender, EventArgs e)
        {
            NT37710_label.Text = NT37710_trackBar.Value.ToString() + "阶";
            NT37710_txtRegData.Text = "51," + NT37710_trackBar.Value.ToString("x2");
            NT37710_RegWR_Click(NT37710_51RegW, e);
        }
        private void NT37710_RegWR_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;
            string strLine = Convert.ToString(NT37710_txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组

            switch (btnTmp.Name)
            {
                case "NT37710_RegW":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x2A;
                        Send_buf[1] = 0x01;
                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "NT37710_51RegW":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x2A;
                        Send_buf[1] = 0x03;
                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "NT37710_RegR":
                    {
                        Setting.TempRecord.NT37710CmdType = 0x02;
                        try
                        {
                            DataNum = Convert.ToInt32(NT37710_txtDataNum.Text) + 1;
                            Setting.TempRecord.cmdLen = DataNum + 5;
                            Send_buf = new byte[DataNum + 5];
                            Send_buf[0] = 0x2A;
                            Send_buf[1] = 0x02;
                            Send_buf[2] = byte.Parse(Convert.ToString(DataNum));
                            Send_buf[3] = byte.Parse((Convert.ToInt32(arr[0], 16)).ToString());
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + DataNum - 2], out Send_buf[5 + DataNum - 1]);
                        }
                        catch
                        {
                            MessageBox.Show("读取长度有误，请检查", "错误");
                            break;
                        }
                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + DataNum);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                default: break;
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        private void NT37710_GammaW_One_key_Click(object sender, EventArgs e)
        {

        }
        private void NT37710_GAMMA_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Send_buf = new byte[54];
            Setting.TempRecord.cmdLen = 54;
            Send_buf[0] = 0x2A; //NT37710
            Send_buf[2] = 49;  //24绑点*2+1cmd=49

            switch (btnTmp.Name)
            {
                case "NT37710_GammaR_Red":
                    {
                        Setting.TempRecord.NT37710CmdType = 0x03;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = Convert.ToByte(((Convert.ToByte(BF_data.Value.ToString()) & 0x0f) << 4) + 0x00);
                    }
                    break;
                case "NT37710_GammaR_Green":
                    {
                        Setting.TempRecord.NT37710CmdType = 0x04;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = Convert.ToByte(((Convert.ToByte(BF_data.Value.ToString()) & 0x0f) << 4) + 0x01);
                    }
                    break;
                case "NT37710_GammaR_Blue":
                    {
                        Setting.TempRecord.NT37710CmdType = 0x05;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = Convert.ToByte(((Convert.ToByte(BF_data.Value.ToString()) & 0x0f) << 4) + 0x02);
                    }
                    break;
                case "NT37710_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;//写标志
                        Send_buf[3] = Convert.ToByte(((Convert.ToByte(BF_data.Value.ToString()) & 0x0f) << 4) + 0x00);
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(NT37710_R0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(NT37710_R0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(NT37710_R1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(NT37710_R1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(NT37710_R3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(NT37710_R3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(NT37710_R5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(NT37710_R5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(NT37710_R7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(NT37710_R7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(NT37710_R9.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(NT37710_R9.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(NT37710_R11.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(NT37710_R11.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(NT37710_R13.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(NT37710_R13.Value.ToString())) & 0xff);

                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(NT37710_R15.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(NT37710_R15.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(NT37710_R17.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(NT37710_R17.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(NT37710_R19.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(NT37710_R19.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(NT37710_R23.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(NT37710_R23.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(NT37710_R31.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(NT37710_R31.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(NT37710_R47.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(NT37710_R47.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(NT37710_R63.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(NT37710_R63.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(NT37710_R79.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(NT37710_R79.Value.ToString())) & 0xff);

                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(NT37710_R95.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(NT37710_R95.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(NT37710_R111.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(NT37710_R111.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(NT37710_R127.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(NT37710_R127.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(NT37710_R159.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(NT37710_R159.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(NT37710_R191.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(NT37710_R191.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(NT37710_R223.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(NT37710_R223.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(NT37710_R255.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(NT37710_R255.Value.ToString())) & 0xff);
                        Send_buf[50] = 0x00;
                        Send_buf[51] = 0x00;
                    }
                    break;
                case "NT37710_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;//写标志
                        Send_buf[3] = Convert.ToByte(((Convert.ToByte(BF_data.Value.ToString()) & 0x0f) << 4) + 0x01);
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(NT37710_G0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(NT37710_G0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(NT37710_G1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(NT37710_G1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(NT37710_G3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(NT37710_G3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(NT37710_G5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(NT37710_G5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(NT37710_G7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(NT37710_G7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(NT37710_G9.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(NT37710_G9.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(NT37710_G11.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(NT37710_G11.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(NT37710_G13.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(NT37710_G13.Value.ToString())) & 0xff);

                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(NT37710_G15.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(NT37710_G15.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(NT37710_G17.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(NT37710_G17.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(NT37710_G19.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(NT37710_G19.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(NT37710_G23.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(NT37710_G23.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(NT37710_G31.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(NT37710_G31.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(NT37710_G47.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(NT37710_G47.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(NT37710_G63.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(NT37710_G63.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(NT37710_G79.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(NT37710_G79.Value.ToString())) & 0xff);

                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(NT37710_G95.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(NT37710_G95.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(NT37710_G111.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(NT37710_G111.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(NT37710_G127.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(NT37710_G127.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(NT37710_G159.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(NT37710_G159.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(NT37710_G191.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(NT37710_G191.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(NT37710_G223.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(NT37710_G223.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(NT37710_G255.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(NT37710_G255.Value.ToString())) & 0xff);
                        Send_buf[50] = 0x00;
                        Send_buf[51] = 0x00;
                    }
                    break;
                case "NT37710_GammaW_Blue":
                    {
                        Send_buf[1] = 0x08;//写标志
                        Send_buf[3] = Convert.ToByte(((Convert.ToByte(BF_data.Value.ToString()) & 0x0f) << 4) + 0x02);
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(NT37710_B0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(NT37710_B0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(NT37710_B1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(NT37710_B1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(NT37710_B3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(NT37710_B3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(NT37710_B5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(NT37710_B5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(NT37710_B7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(NT37710_B7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(NT37710_B9.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(NT37710_B9.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(NT37710_B11.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(NT37710_B11.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(NT37710_B13.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(NT37710_B13.Value.ToString())) & 0xff);

                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(NT37710_B15.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(NT37710_B15.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(NT37710_B17.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(NT37710_B17.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(NT37710_B19.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(NT37710_B19.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(NT37710_B23.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(NT37710_B23.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(NT37710_B31.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(NT37710_B31.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(NT37710_B47.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(NT37710_B47.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(NT37710_B63.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(NT37710_B63.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(NT37710_B79.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(NT37710_B79.Value.ToString())) & 0xff);

                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(NT37710_B95.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(NT37710_B95.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(NT37710_B111.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(NT37710_B111.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(NT37710_B127.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(NT37710_B127.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(NT37710_B159.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(NT37710_B159.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(NT37710_B191.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(NT37710_B191.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(NT37710_B223.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(NT37710_B223.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(NT37710_B255.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(NT37710_B255.Value.ToString())) & 0xff);
                        Send_buf[50] = 0x00;
                        Send_buf[51] = 0x00;
                    }
                    break;
                default: break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[52], out Send_buf[53]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 54);   //NT37710
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        private void NT37710_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[13];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 13;

            Send_buf[0] = 0x2A;
            Send_buf[2] = 0x08;
            switch (btnTmp.Name)
            {
                case "NT37710_OTP":         //otp
                    {
                        /*------------NT37710 MTP PAGE0 GROUP----------*/
                        if (P0_A1.Checked == true)
                            Send_buf[4] |= 0x08;
                        else
                            Send_buf[4] &= 0xf7;
                        if (P0_A2.Checked == true)
                            Send_buf[4] |= 0x04;
                        else
                            Send_buf[4] &= 0xfb;
                        if (P0_ASPR.Checked == true)
                            Send_buf[4] |= 0x02;
                        else
                            Send_buf[4] &= 0xfd;
                        if (P0_ACM.Checked == true)
                            Send_buf[4] |= 0x01;
                        else
                            Send_buf[4] &= 0xfe;
                        /*------------NT37710 MTP PAGE1 GROUP----------*/
                        if (P1_A1.Checked == true)
                            Send_buf[5] |= 0x04;
                        else
                            Send_buf[5] &= 0xfb;
                        if (P1_A2.Checked == true)
                            Send_buf[5] |= 0x02;
                        else
                            Send_buf[5] &= 0xfd;
                        if (P1_ASPR.Checked == true)
                            Send_buf[5] |= 0x01;
                        else
                            Send_buf[5] &= 0xfe;
                        /*------------NT37710 MTP PAGE2 GROUP----------*/
                        if (P2_ASPR_N.Checked == true)
                            Send_buf[6] |= 0x80;
                        else
                            Send_buf[6] &= 0x7f;
                        if (P2_ASPR.Checked == true)
                            Send_buf[6] |= 0x01;
                        else
                            Send_buf[6] &= 0xfe;
                        /*------------NT37710 MTP PAGE3 GROUP----------*/
                        if (P3_A2.Checked == true)
                            Send_buf[7] |= 0x01;
                        else
                            Send_buf[7] &= 0xfe;
                        /*------------NT37710 MTP PAGE5 GROUP----------*/
                        if (P5_A2.Checked == true)
                            Send_buf[8] |= 0x01;
                        else
                            Send_buf[8] &= 0xfe;
                        /*------------NT37710 MTP PAGE6 GROUP----------*/
                        if (P6_A2.Checked == true)
                            Send_buf[9] |= 0x01;
                        else
                            Send_buf[9] &= 0xfe;
                        /*------------NT37710 MTP PAGE7 GROUP----------*/
                        if (P7_ACM.Checked == true)
                            Send_buf[10] |= 0x02;
                        else
                            Send_buf[10] &= 0xfd;
                        if (P7_ASPR.Checked == true)
                            Send_buf[10] |= 0x01;
                        else
                            Send_buf[10] &= 0xfe;
                        /*------------end----------*/

                        Send_buf[1] = 0x0A;
                        {       //保存待otp的gamma
                            FileStream fs = new FileStream("../OTP_gamma_NT37710.txt", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Close();
                            StreamWriter sw = new StreamWriter(fs.Name, false, Encoding.UTF8);
                            string str = null;
                            str = str + NT37710_R0.Text + "," + NT37710_G0.Text + "," + NT37710_B0.Text + "\r\n";
                            str = str + NT37710_R1.Text + "," + NT37710_G1.Text + "," + NT37710_B1.Text + "\r\n";
                            str = str + NT37710_R3.Text + "," + NT37710_G3.Text + "," + NT37710_B3.Text + "\r\n";
                            str = str + NT37710_R5.Text + "," + NT37710_G5.Text + "," + NT37710_B5.Text + "\r\n";
                            str = str + NT37710_R7.Text + "," + NT37710_G7.Text + "," + NT37710_B7.Text + "\r\n";
                            str = str + NT37710_R9.Text + "," + NT37710_G9.Text + "," + NT37710_B9.Text + "\r\n";
                            str = str + NT37710_R11.Text + "," + NT37710_G11.Text + "," + NT37710_B11.Text + "\r\n";
                            str = str + NT37710_R13.Text + "," + NT37710_G13.Text + "," + NT37710_B13.Text + "\r\n";
                            str = str + NT37710_R15.Text + "," + NT37710_G15.Text + "," + NT37710_B15.Text + "\r\n";
                            str = str + NT37710_R17.Text + "," + NT37710_G17.Text + "," + NT37710_B17.Text + "\r\n";
                            str = str + NT37710_R19.Text + "," + NT37710_G19.Text + "," + NT37710_B19.Text + "\r\n";
                            str = str + NT37710_R23.Text + "," + NT37710_G23.Text + "," + NT37710_B23.Text + "\r\n";
                            str = str + NT37710_R31.Text + "," + NT37710_G31.Text + "," + NT37710_B31.Text + "\r\n";
                            str = str + NT37710_R47.Text + "," + NT37710_G47.Text + "," + NT37710_B47.Text + "\r\n";
                            str = str + NT37710_R63.Text + "," + NT37710_G63.Text + "," + NT37710_B63.Text + "\r\n";
                            str = str + NT37710_R79.Text + "," + NT37710_G79.Text + "," + NT37710_B79.Text + "\r\n";
                            str = str + NT37710_R95.Text + "," + NT37710_G95.Text + "," + NT37710_B95.Text + "\r\n";
                            str = str + NT37710_R111.Text + "," + NT37710_G111.Text + "," + NT37710_B111.Text + "\r\n";
                            str = str + NT37710_R127.Text + "," + NT37710_G127.Text + "," + NT37710_B127.Text + "\r\n";
                            str = str + NT37710_R159.Text + "," + NT37710_G159.Text + "," + NT37710_B159.Text + "\r\n";
                            str = str + NT37710_R191.Text + "," + NT37710_G191.Text + "," + NT37710_B191.Text + "\r\n";
                            str = str + NT37710_R223.Text + "," + NT37710_G223.Text + "," + NT37710_B223.Text + "\r\n";
                            str = str + NT37710_R255.Text + "," + NT37710_G255.Text + "," + NT37710_B255.Text + "\r\n";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                        }
                    }
                    break;
                /*
            case "NT37710_OTP_ID":         //Read
                {
                    Setting.TempRecord.NT37710CmdType = 0x01;   //读普通寄存器
                    Send_buf[1] = 0x0C;
                }
                break;

            case "NT37710_OTP_time_Read":         //Read
                {
                    Setting.TempRecord.NT37710CmdType = 0x01;   //读普通寄存器
                    Send_buf[1] = 0x0B;
                }
                break;
                */

                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[11], out Send_buf[12]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 13);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }


        private int[] Parttern_NT37710 = new int[22] { 255, 223, 191, 159, 127, 111, 95, 79, 63, 47, 31, 23, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1 };
        private void CalculateNT_Click_1(object sender, EventArgs e)
        {
            textNT255.Text = (Math.Pow((Parttern_NT37710[0] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT223.Text = (Math.Pow((Parttern_NT37710[1] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT191.Text = (Math.Pow((Parttern_NT37710[2] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT159.Text = (Math.Pow((Parttern_NT37710[3] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT127.Text = (Math.Pow((Parttern_NT37710[4] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT111.Text = (Math.Pow((Parttern_NT37710[5] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT95.Text = (Math.Pow((Parttern_NT37710[6] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT79.Text = (Math.Pow((Parttern_NT37710[7] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT63.Text = (Math.Pow((Parttern_NT37710[8] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT47.Text = (Math.Pow((Parttern_NT37710[9] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT31.Text = (Math.Pow((Parttern_NT37710[10] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT23.Text = (Math.Pow((Parttern_NT37710[11] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT19.Text = (Math.Pow((Parttern_NT37710[12] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT17.Text = (Math.Pow((Parttern_NT37710[13] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT15.Text = (Math.Pow((Parttern_NT37710[14] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT13.Text = (Math.Pow((Parttern_NT37710[15] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT11.Text = (Math.Pow((Parttern_NT37710[16] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT9.Text = (Math.Pow((Parttern_NT37710[17] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT7.Text = (Math.Pow((Parttern_NT37710[18] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT5.Text = (Math.Pow((Parttern_NT37710[19] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT3.Text = (Math.Pow((Parttern_NT37710[20] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");
            textNT1.Text = (Math.Pow((Parttern_NT37710[21] / 255.0), Convert.ToDouble(textNTGamma.Text)) * Convert.ToDouble(textNTlum.Text)).ToString("F4");

        }
        private void btnNTStop_Click(object sender, EventArgs e)
        {
            frmHelp.T20.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }

        private void btnAutoGgammaNT(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;
            D_lums = new double[22, 3];
            D_lum = new double[22];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            D_lum[0] = Convert.ToDouble(textNT255.Text);
            D_lum[1] = Convert.ToDouble(textNT223.Text);
            D_lum[2] = Convert.ToDouble(textNT191.Text);
            D_lum[3] = Convert.ToDouble(textNT159.Text);
            D_lum[4] = Convert.ToDouble(textNT127.Text);
            D_lum[5] = Convert.ToDouble(textNT111.Text);
            D_lum[6] = Convert.ToDouble(textNT95.Text);
            D_lum[7] = Convert.ToDouble(textNT79.Text);
            D_lum[8] = Convert.ToDouble(textNT63.Text);
            D_lum[9] = Convert.ToDouble(textNT47.Text);
            D_lum[10] = Convert.ToDouble(textNT31.Text);
            D_lum[11] = Convert.ToDouble(textNT23.Text);
            D_lum[12] = Convert.ToDouble(textNT19.Text);
            D_lum[13] = Convert.ToDouble(textNT17.Text);
            D_lum[14] = Convert.ToDouble(textNT15.Text);
            D_lum[15] = Convert.ToDouble(textNT13.Text);
            D_lum[16] = Convert.ToDouble(textNT11.Text);
            D_lum[17] = Convert.ToDouble(textNT9.Text);
            D_lum[18] = Convert.ToDouble(textNT7.Text);
            D_lum[19] = Convert.ToDouble(textNT5.Text);
            D_lum[20] = Convert.ToDouble(textNT3.Text);
            D_lum[21] = Convert.ToDouble(textNT1.Text);
            D_x = Convert.ToDouble(textNTx.Text);
            D_y = Convert.ToDouble(textNTy.Text);
            Lr_d = CaSDKObj.R_y * ((D_y - CaSDKObj.G_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.G_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.G_y) * (D_x - CaSDKObj.R_x) + (D_x - CaSDKObj.G_x) * (CaSDKObj.R_y - D_y));
            Lb_d = 1.0;
            Lg_d = CaSDKObj.G_y * ((D_y - CaSDKObj.R_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.R_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.R_y) * (D_x - CaSDKObj.G_x) + (D_x - CaSDKObj.R_x) * (CaSDKObj.G_y - D_y));

            for (int i = 0; i < 22; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }

            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(textNTlum_off.Text);
                        x_off = Convert.ToDouble(textNTx_off.Text);
                        y_off = Convert.ToDouble(textNTy_off.Text);
                        NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                        NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                        NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                        Application.DoEvents();
                        frmHelp.OLED_Show_Click(frmHelp.btnwhite, e);
                        frmHelp.T20.Enabled = true;
                    }
                    break;
                case 2://寄存器值与亮度反比
                    break;
                default:
                    break;
            }
        }
        private void NT37710_auto_gamma(Object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if ((frmHelp.CASDK_LUM < (D_lum[index] + lum_off)) && (frmHelp.CASDK_LUM > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((frmHelp.CASDK_y < (D_y + y_off)) && (frmHelp.CASDK_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((frmHelp.CASDK_x < (D_x + x_off)) && (frmHelp.CASDK_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                frmHelp.T20.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 22)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "NT37710 gamma调试完毕!\r\n";
                }
                if (index < 22)
                {
                    switch (index)
                    {
                        case 1:
                            {
                                lum_off = Convert.ToDouble(textNT223_off.Text);
                                NT37710_R223.Value = NT37710_R255.Value - 0X30;
                                NT37710_G223.Value = NT37710_G255.Value - 0X30;
                                NT37710_B223.Value = NT37710_B255.Value - 0X30;
                                NT37710_R191.Value = NT37710_R223.Value - 0X30;
                                NT37710_G191.Value = NT37710_G223.Value - 0X30;
                                NT37710_B191.Value = NT37710_B223.Value - 0X30;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 2:
                            {
                                lum_off = Convert.ToDouble(textNT191_off.Text);
                                NT37710_R191.Value = NT37710_R223.Value - 0X30;
                                NT37710_G191.Value = NT37710_G223.Value - 0X30;
                                NT37710_B191.Value = NT37710_B223.Value - 0X30;
                                NT37710_R159.Value = NT37710_R191.Value - 0X30;
                                NT37710_G159.Value = NT37710_G191.Value - 0X30;
                                NT37710_B159.Value = NT37710_B191.Value - 0X30;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 3:
                            {
                                lum_off = Convert.ToDouble(textNT159_off.Text);
                                NT37710_R159.Value = NT37710_R191.Value - 0X30;
                                NT37710_G159.Value = NT37710_G191.Value - 0X30;
                                NT37710_B159.Value = NT37710_B191.Value - 0X30;
                                NT37710_R127.Value = NT37710_R159.Value - 0X30;
                                NT37710_G127.Value = NT37710_G159.Value - 0X30;
                                NT37710_B127.Value = NT37710_B159.Value - 0X30;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 4:
                            {
                                lum_off = Convert.ToDouble(textNT127_off.Text) * Convert.ToDouble(textNT127.Text) / 100;
                                NT37710_R127.Value = NT37710_R159.Value - 0X30;
                                NT37710_G127.Value = NT37710_G159.Value - 0X30;
                                NT37710_B127.Value = NT37710_B159.Value - 0X30;
                                NT37710_R111.Value = NT37710_R127.Value - 0X30;
                                NT37710_G111.Value = NT37710_G127.Value - 0X30;
                                NT37710_B111.Value = NT37710_B127.Value - 0X30;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 5:
                            {
                                lum_off = Convert.ToDouble(textNT111_off.Text) * Convert.ToDouble(textNT111.Text) / 100;
                                NT37710_R111.Value = NT37710_R127.Value - 0X20;
                                NT37710_G111.Value = NT37710_G127.Value - 0X20;
                                NT37710_B111.Value = NT37710_B127.Value - 0X20;
                                NT37710_R95.Value = NT37710_R111.Value - 0X20;
                                NT37710_G95.Value = NT37710_G111.Value - 0X20;
                                NT37710_B95.Value = NT37710_B111.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 6:
                            {
                                lum_off = Convert.ToDouble(textNT95_off.Text) * Convert.ToDouble(textNT95.Text) / 100;
                                NT37710_R95.Value = NT37710_R111.Value - 0X20;
                                NT37710_G95.Value = NT37710_G111.Value - 0X20;
                                NT37710_B95.Value = NT37710_B111.Value - 0X20;
                                NT37710_R79.Value = NT37710_R95.Value - 0X20;
                                NT37710_G79.Value = NT37710_G95.Value - 0X20;
                                NT37710_B79.Value = NT37710_B95.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 7:
                            {
                                lum_off = Convert.ToDouble(textNT79_off.Text) * Convert.ToDouble(textNT79.Text) / 100;
                                NT37710_R79.Value = NT37710_R95.Value - 0X20;
                                NT37710_G79.Value = NT37710_G95.Value - 0X20;
                                NT37710_B79.Value = NT37710_B95.Value - 0X20;
                                NT37710_R63.Value = NT37710_R79.Value - 0X20;
                                NT37710_G63.Value = NT37710_G79.Value - 0X20;
                                NT37710_B63.Value = NT37710_B79.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 8:
                            {
                                lum_off = Convert.ToDouble(textNT63_off.Text) * Convert.ToDouble(textNT63.Text) / 100;
                                NT37710_R63.Value = NT37710_R79.Value - 0X20;
                                NT37710_G63.Value = NT37710_G79.Value - 0X20;
                                NT37710_B63.Value = NT37710_B79.Value - 0X20;
                                NT37710_R47.Value = NT37710_R63.Value - 0X20;
                                NT37710_G47.Value = NT37710_G63.Value - 0X20;
                                NT37710_B47.Value = NT37710_B63.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 9:
                            {
                                lum_off = Convert.ToDouble(textNT47_off.Text) * Convert.ToDouble(textNT47.Text) / 100;
                                NT37710_R47.Value = NT37710_R63.Value - 0X20;
                                NT37710_G47.Value = NT37710_G63.Value - 0X20;
                                NT37710_B47.Value = NT37710_B63.Value - 0X20;
                                NT37710_R31.Value = NT37710_R47.Value - 0X20;
                                NT37710_G31.Value = NT37710_G47.Value - 0X20;
                                NT37710_B31.Value = NT37710_B47.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 10:
                            {
                                lum_off = Convert.ToDouble(textNT31_off.Text) * Convert.ToDouble(textNT31.Text) / 100;
                                NT37710_R31.Value = NT37710_R47.Value - 0X20;
                                NT37710_G31.Value = NT37710_G47.Value - 0X20;
                                NT37710_B31.Value = NT37710_B47.Value - 0X20;
                                NT37710_R23.Value = NT37710_R31.Value - 0X20;
                                NT37710_G23.Value = NT37710_G31.Value - 0X20;
                                NT37710_B23.Value = NT37710_B31.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 11:
                            {
                                lum_off = Convert.ToDouble(textNT23_off.Text) * Convert.ToDouble(textNT23.Text) / 100;
                                NT37710_R23.Value = NT37710_R31.Value - 0X20;
                                NT37710_G23.Value = NT37710_G31.Value - 0X20;
                                NT37710_B23.Value = NT37710_B31.Value - 0X20;
                                NT37710_R19.Value = NT37710_R23.Value - 0X20;
                                NT37710_G19.Value = NT37710_G23.Value - 0X20;
                                NT37710_B19.Value = NT37710_B23.Value - 0X20;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 12:
                            {
                                lum_off = Convert.ToDouble(textNT19_off.Text) * Convert.ToDouble(textNT19.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R19.Value = NT37710_R23.Value - 0X10;
                                NT37710_G19.Value = NT37710_G23.Value - 0X10;
                                NT37710_B19.Value = NT37710_B23.Value - 0X10;
                                NT37710_R17.Value = NT37710_R19.Value - 0X10;
                                NT37710_G17.Value = NT37710_G19.Value - 0X10;
                                NT37710_B17.Value = NT37710_B19.Value - 0X10;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 13:

                            {
                                lum_off = Convert.ToDouble(textNT17_off.Text) * Convert.ToDouble(textNT17.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R17.Value = NT37710_R19.Value - 0X0A;
                                NT37710_G17.Value = NT37710_G19.Value - 0X0A;
                                NT37710_B17.Value = NT37710_B19.Value - 0X0A;
                                NT37710_R15.Value = NT37710_R17.Value - 0X0A;
                                NT37710_G15.Value = NT37710_G17.Value - 0X0A;
                                NT37710_B15.Value = NT37710_B17.Value - 0X0A;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 14:
                            {
                                lum_off = Convert.ToDouble(textNT15_off.Text) * Convert.ToDouble(textNT15.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R15.Value = NT37710_R17.Value - 0X0A;
                                NT37710_G15.Value = NT37710_G17.Value - 0X0A;
                                NT37710_B15.Value = NT37710_B17.Value - 0X0A;
                                NT37710_R13.Value = NT37710_R15.Value - 0X0A;
                                NT37710_G13.Value = NT37710_G15.Value - 0X0A;
                                NT37710_B13.Value = NT37710_B15.Value - 0X0A;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 15:
                            {
                                lum_off = Convert.ToDouble(textNT13_off.Text) * Convert.ToDouble(textNT13.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R13.Value = NT37710_R15.Value - 0X0A;
                                NT37710_G13.Value = NT37710_G15.Value - 0X0A;
                                NT37710_B13.Value = NT37710_B15.Value - 0X0A;
                                NT37710_R11.Value = NT37710_R13.Value - 0X0A;
                                NT37710_G11.Value = NT37710_G13.Value - 0X0A;
                                NT37710_B11.Value = NT37710_B13.Value - 0X0A;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 16:
                            {
                                lum_off = Convert.ToDouble(textNT11_off.Text) * Convert.ToDouble(textNT11.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R11.Value = NT37710_R13.Value - 0X0A;
                                NT37710_G11.Value = NT37710_G13.Value - 0X0A;
                                NT37710_B11.Value = NT37710_B13.Value - 0X0A;
                                NT37710_R9.Value = NT37710_R11.Value - 0X0A;
                                NT37710_G9.Value = NT37710_G11.Value - 0X0A;
                                NT37710_B9.Value = NT37710_B11.Value - 0X0A;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 17:
                            {
                                lum_off = Convert.ToDouble(textNT9_off.Text) * Convert.ToDouble(textNT9.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R9.Value = NT37710_R11.Value - 0X0A;
                                NT37710_G9.Value = NT37710_G11.Value - 0X0A;
                                NT37710_B9.Value = NT37710_B11.Value - 0X0A;
                                NT37710_R7.Value = NT37710_R9.Value - 0X0A;
                                NT37710_G7.Value = NT37710_G9.Value - 0X0A;
                                NT37710_B7.Value = NT37710_B9.Value - 0X0A;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 18:
                            {
                                lum_off = Convert.ToDouble(textNT7_off.Text) * Convert.ToDouble(textNT7.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R7.Value = NT37710_R9.Value - 0X10;
                                NT37710_G7.Value = NT37710_G9.Value - 0X10;
                                NT37710_B7.Value = NT37710_B9.Value - 0X10;
                                NT37710_R5.Value = NT37710_R7.Value - 0X10;
                                NT37710_G5.Value = NT37710_G7.Value - 0X10;
                                NT37710_B5.Value = NT37710_B7.Value - 0X10;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 19:
                            {
                                lum_off = Convert.ToDouble(textNT5_off.Text) * Convert.ToDouble(textNT5.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R5.Value = NT37710_R7.Value - 0X10;
                                NT37710_G5.Value = NT37710_G7.Value - 0X10;
                                NT37710_B5.Value = NT37710_B7.Value - 0X10;
                                NT37710_R3.Value = NT37710_R5.Value - 0X10;
                                NT37710_G3.Value = NT37710_G5.Value - 0X10;
                                NT37710_B3.Value = NT37710_B5.Value - 0X10;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 20:
                            {
                                lum_off = Convert.ToDouble(textNT3_off.Text) * Convert.ToDouble(textNT3.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R3.Value = NT37710_R5.Value - 0X10;
                                NT37710_G3.Value = NT37710_G5.Value - 0X10;
                                NT37710_B3.Value = NT37710_B5.Value - 0X10;
                                NT37710_R1.Value = NT37710_R3.Value - 0X10;
                                NT37710_G1.Value = NT37710_G3.Value - 0X10;
                                NT37710_B1.Value = NT37710_B3.Value - 0X10;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                        case 21:
                            {
                                lum_off = Convert.ToDouble(textNT1_off.Text) * Convert.ToDouble(textNT1.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                                NT37710_R1.Value = NT37710_R3.Value - 0X30;
                                NT37710_G1.Value = NT37710_G3.Value - 0X30;
                                NT37710_B1.Value = NT37710_B3.Value - 0X30;
                                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
                            }
                            break;
                    }
                    frmHelp.numPatternR.Value = Parttern_NT37710[index];
                    frmHelp.numPatternG.Value = Parttern_NT37710[index];
                    frmHelp.numPatternB.Value = Parttern_NT37710[index];
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, e);//写入Pattern参数
                    Thread.Sleep(10); //1秒=1000毫秒，
                    frmHelp.T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                CaSDKObj.YUV_to_RGB(frmHelp.CASDK_y, frmHelp.CASDK_x, out Lr_t, out Lb_t, out Lg_t);
                lumr = frmHelp.CASDK_LUM * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = frmHelp.CASDK_LUM * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = frmHelp.CASDK_LUM * Lb_t / (Lr_t + Lg_t + Lb_t);

                switch (index)
                {
                    case 0:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R255.Value = NT37710_R255.Value - step_h;
                                    else NT37710_R255.Value = NT37710_R255.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R255.Value = NT37710_R255.Value - step_l;
                                    else NT37710_R255.Value = NT37710_R255.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G255.Value = NT37710_G255.Value - step_h;
                                    else NT37710_G255.Value = NT37710_G255.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G255.Value = NT37710_G255.Value - step_l;
                                    else NT37710_G255.Value = NT37710_G255.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B255.Value = NT37710_B255.Value - step_h;
                                    else NT37710_B255.Value = NT37710_B255.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B255.Value = NT37710_B255.Value - step_l;
                                    else NT37710_B255.Value = NT37710_B255.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 1:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R223.Value = NT37710_R223.Value - step_h;
                                    else NT37710_R223.Value = NT37710_R223.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R223.Value = NT37710_R223.Value - step_l;
                                    else NT37710_R223.Value = NT37710_R223.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G223.Value = NT37710_G223.Value - step_h;
                                    else NT37710_G223.Value = NT37710_G223.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G223.Value = NT37710_G223.Value - step_l;
                                    else NT37710_G223.Value = NT37710_G223.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B223.Value = NT37710_B223.Value - step_h;
                                    else NT37710_B223.Value = NT37710_B223.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B223.Value = NT37710_B223.Value - step_l;
                                    else NT37710_B223.Value = NT37710_B223.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 2:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R191.Value = NT37710_R191.Value - step_h;
                                    else NT37710_R191.Value = NT37710_R191.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R191.Value = NT37710_R191.Value - step_l;
                                    else NT37710_R191.Value = NT37710_R191.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G191.Value = NT37710_G191.Value - step_h;
                                    else NT37710_G191.Value = NT37710_G191.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G191.Value = NT37710_G191.Value - step_l;
                                    else NT37710_G191.Value = NT37710_G191.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B191.Value = NT37710_B191.Value - step_h;
                                    else NT37710_B191.Value = NT37710_B191.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B191.Value = NT37710_B191.Value - step_l;
                                    else NT37710_B191.Value = NT37710_B191.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 3:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R159.Value = NT37710_R159.Value - step_h;
                                    else NT37710_R159.Value = NT37710_R159.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R159.Value = NT37710_R159.Value - step_l;
                                    else NT37710_R159.Value = NT37710_R159.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G159.Value = NT37710_G159.Value - step_h;
                                    else NT37710_G159.Value = NT37710_G159.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G159.Value = NT37710_G159.Value - step_l;
                                    else NT37710_G159.Value = NT37710_G159.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B159.Value = NT37710_B159.Value - step_h;
                                    else NT37710_B159.Value = NT37710_B159.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B159.Value = NT37710_B159.Value - step_l;
                                    else NT37710_B159.Value = NT37710_B159.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 4:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R127.Value = NT37710_R127.Value - step_h;
                                    else NT37710_R127.Value = NT37710_R127.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R127.Value = NT37710_R127.Value - step_l;
                                    else NT37710_R127.Value = NT37710_R127.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G127.Value = NT37710_G127.Value - step_h;
                                    else NT37710_G127.Value = NT37710_G127.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G127.Value = NT37710_G127.Value - step_l;
                                    else NT37710_G127.Value = NT37710_G127.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B127.Value = NT37710_B127.Value - step_h;
                                    else NT37710_B127.Value = NT37710_B127.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B127.Value = NT37710_B127.Value - step_l;
                                    else NT37710_B127.Value = NT37710_B127.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 5:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R111.Value = NT37710_R111.Value - step_h;
                                    else NT37710_R111.Value = NT37710_R111.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R111.Value = NT37710_R111.Value - step_l;
                                    else NT37710_R111.Value = NT37710_R111.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G111.Value = NT37710_G111.Value - step_h;
                                    else NT37710_G111.Value = NT37710_G111.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G111.Value = NT37710_G111.Value - step_l;
                                    else NT37710_G111.Value = NT37710_G111.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B111.Value = NT37710_B111.Value - step_h;
                                    else NT37710_B111.Value = NT37710_B111.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B111.Value = NT37710_B111.Value - step_l;
                                    else NT37710_B111.Value = NT37710_B111.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 6:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R95.Value = NT37710_R95.Value - step_h;
                                    else NT37710_R95.Value = NT37710_R95.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R95.Value = NT37710_R95.Value - step_l;
                                    else NT37710_R95.Value = NT37710_R95.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G95.Value = NT37710_G95.Value - step_h;
                                    else NT37710_G95.Value = NT37710_G95.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G95.Value = NT37710_G95.Value - step_l;
                                    else NT37710_G95.Value = NT37710_G95.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B95.Value = NT37710_B95.Value - step_h;
                                    else NT37710_B95.Value = NT37710_B95.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B95.Value = NT37710_B95.Value - step_l;
                                    else NT37710_B95.Value = NT37710_B95.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 7:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R79.Value = NT37710_R79.Value - step_h;
                                    else NT37710_R79.Value = NT37710_R79.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R79.Value = NT37710_R79.Value - step_l;
                                    else NT37710_R79.Value = NT37710_R79.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G79.Value = NT37710_G79.Value - step_h;
                                    else NT37710_G79.Value = NT37710_G79.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G79.Value = NT37710_G79.Value - step_l;
                                    else NT37710_G79.Value = NT37710_G79.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B79.Value = NT37710_B79.Value - step_h;
                                    else NT37710_B79.Value = NT37710_B79.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B79.Value = NT37710_B79.Value - step_l;
                                    else NT37710_B79.Value = NT37710_B79.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 8:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R63.Value = NT37710_R63.Value - step_h;
                                    else NT37710_R63.Value = NT37710_R63.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R63.Value = NT37710_R63.Value - step_l;
                                    else NT37710_R63.Value = NT37710_R63.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G63.Value = NT37710_G63.Value - step_h;
                                    else NT37710_G63.Value = NT37710_G63.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G63.Value = NT37710_G63.Value - step_l;
                                    else NT37710_G63.Value = NT37710_G63.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B63.Value = NT37710_B63.Value - step_h;
                                    else NT37710_B63.Value = NT37710_B63.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B63.Value = NT37710_B63.Value - step_l;
                                    else NT37710_B63.Value = NT37710_B63.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 9:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R47.Value = NT37710_R47.Value - step_h;
                                    else NT37710_R47.Value = NT37710_R47.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R47.Value = NT37710_R47.Value - step_l;
                                    else NT37710_R47.Value = NT37710_R47.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G47.Value = NT37710_G47.Value - step_h;
                                    else NT37710_G47.Value = NT37710_G47.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G47.Value = NT37710_G47.Value - step_l;
                                    else NT37710_G47.Value = NT37710_G47.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B47.Value = NT37710_B47.Value - step_h;
                                    else NT37710_B47.Value = NT37710_B47.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B47.Value = NT37710_B47.Value - step_l;
                                    else NT37710_B47.Value = NT37710_B47.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 10:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R31.Value = NT37710_R31.Value - step_h;
                                    else NT37710_R31.Value = NT37710_R31.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R31.Value = NT37710_R31.Value - step_l;
                                    else NT37710_R31.Value = NT37710_R31.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G31.Value = NT37710_G31.Value - step_h;
                                    else NT37710_G31.Value = NT37710_G31.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G31.Value = NT37710_G31.Value - step_l;
                                    else NT37710_G31.Value = NT37710_G31.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B31.Value = NT37710_B31.Value - step_h;
                                    else NT37710_B31.Value = NT37710_B31.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B31.Value = NT37710_B31.Value - step_l;
                                    else NT37710_B31.Value = NT37710_B31.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 11:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R23.Value = NT37710_R23.Value - step_h;
                                    else NT37710_R23.Value = NT37710_R23.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R23.Value = NT37710_R23.Value - step_l;
                                    else NT37710_R23.Value = NT37710_R23.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G23.Value = NT37710_G23.Value - step_h;
                                    else NT37710_G23.Value = NT37710_G23.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G23.Value = NT37710_G23.Value - step_l;
                                    else NT37710_G23.Value = NT37710_G23.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B23.Value = NT37710_B23.Value - step_h;
                                    else NT37710_B23.Value = NT37710_B23.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B23.Value = NT37710_B23.Value - step_l;
                                    else NT37710_B23.Value = NT37710_B23.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 12://20阶以下
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R19.Value = NT37710_R19.Value - step_h;
                                    else NT37710_R19.Value = NT37710_R19.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R19.Value = NT37710_R19.Value - step_l;
                                    else NT37710_R19.Value = NT37710_R19.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G19.Value = NT37710_G19.Value - step_h;
                                    else NT37710_G19.Value = NT37710_G19.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G19.Value = NT37710_G19.Value - step_l;
                                    else NT37710_G19.Value = NT37710_G19.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B19.Value = NT37710_B19.Value - step_h;
                                    else NT37710_B19.Value = NT37710_B19.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B19.Value = NT37710_B19.Value - step_l;
                                    else NT37710_B19.Value = NT37710_B19.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 13:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R17.Value = NT37710_R17.Value - step_h;
                                    else NT37710_R17.Value = NT37710_R17.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R17.Value = NT37710_R17.Value - step_l;
                                    else NT37710_R17.Value = NT37710_R17.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G17.Value = NT37710_G17.Value - step_h;
                                    else NT37710_G17.Value = NT37710_G17.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G17.Value = NT37710_G17.Value - step_l;
                                    else NT37710_G17.Value = NT37710_G17.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B17.Value = NT37710_B17.Value - step_h;
                                    else NT37710_B17.Value = NT37710_B17.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B17.Value = NT37710_B17.Value - step_l;
                                    else NT37710_B17.Value = NT37710_B17.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 14:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R15.Value = NT37710_R15.Value - step_h;
                                    else NT37710_R15.Value = NT37710_R15.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R15.Value = NT37710_R15.Value - step_l;
                                    else NT37710_R15.Value = NT37710_R15.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G15.Value = NT37710_G15.Value - step_h;
                                    else NT37710_G15.Value = NT37710_G15.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G15.Value = NT37710_G15.Value - step_l;
                                    else NT37710_G15.Value = NT37710_G15.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B15.Value = NT37710_B15.Value - step_h;
                                    else NT37710_B15.Value = NT37710_B15.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B15.Value = NT37710_B15.Value - step_l;
                                    else NT37710_B15.Value = NT37710_B15.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 15:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R13.Value = NT37710_R13.Value - step_h;
                                    else NT37710_R13.Value = NT37710_R13.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R13.Value = NT37710_R13.Value - step_l;
                                    else NT37710_R13.Value = NT37710_R13.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G13.Value = NT37710_G13.Value - step_h;
                                    else NT37710_G13.Value = NT37710_G13.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G13.Value = NT37710_G13.Value - step_l;
                                    else NT37710_G13.Value = NT37710_G13.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B13.Value = NT37710_B13.Value - step_h;
                                    else NT37710_B13.Value = NT37710_B13.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B13.Value = NT37710_B13.Value - step_l;
                                    else NT37710_B13.Value = NT37710_B13.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 16:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R11.Value = NT37710_R11.Value - step_h;
                                    else NT37710_R11.Value = NT37710_R11.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R11.Value = NT37710_R11.Value - step_l;
                                    else NT37710_R11.Value = NT37710_R11.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G11.Value = NT37710_G11.Value - step_h;
                                    else NT37710_G11.Value = NT37710_G11.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G11.Value = NT37710_G11.Value - step_l;
                                    else NT37710_G11.Value = NT37710_G11.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B11.Value = NT37710_B11.Value - step_h;
                                    else NT37710_B11.Value = NT37710_B11.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B11.Value = NT37710_B11.Value - step_l;
                                    else NT37710_B11.Value = NT37710_B11.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 17:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R9.Value = NT37710_R9.Value - step_h;
                                    else NT37710_R9.Value = NT37710_R9.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R9.Value = NT37710_R9.Value - step_l;
                                    else NT37710_R9.Value = NT37710_R9.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G9.Value = NT37710_G9.Value - step_h;
                                    else NT37710_G9.Value = NT37710_G9.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G9.Value = NT37710_G9.Value - step_l;
                                    else NT37710_G9.Value = NT37710_G9.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B9.Value = NT37710_B9.Value - step_h;
                                    else NT37710_B9.Value = NT37710_B9.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B9.Value = NT37710_B9.Value - step_l;
                                    else NT37710_B9.Value = NT37710_B9.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 18:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R7.Value = NT37710_R7.Value - step_h;
                                    else NT37710_R7.Value = NT37710_R7.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R7.Value = NT37710_R7.Value - step_l;
                                    else NT37710_R7.Value = NT37710_R7.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G7.Value = NT37710_G7.Value - step_h;
                                    else NT37710_G7.Value = NT37710_G7.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G7.Value = NT37710_G7.Value - step_l;
                                    else NT37710_G7.Value = NT37710_G7.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B7.Value = NT37710_B7.Value - step_h;
                                    else NT37710_B7.Value = NT37710_B7.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B7.Value = NT37710_B7.Value - step_l;
                                    else NT37710_B7.Value = NT37710_B7.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 19:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R5.Value = NT37710_R5.Value - step_h;
                                    else NT37710_R5.Value = NT37710_R5.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R5.Value = NT37710_R5.Value - step_l;
                                    else NT37710_R5.Value = NT37710_R5.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G5.Value = NT37710_G5.Value - step_h;
                                    else NT37710_G5.Value = NT37710_G5.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G5.Value = NT37710_G5.Value - step_l;
                                    else NT37710_G5.Value = NT37710_G5.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B5.Value = NT37710_B5.Value - step_h;
                                    else NT37710_B5.Value = NT37710_B5.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B5.Value = NT37710_B5.Value - step_l;
                                    else NT37710_B5.Value = NT37710_B5.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 20:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R3.Value = NT37710_R3.Value - step_h;
                                    else NT37710_R3.Value = NT37710_R3.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R3.Value = NT37710_R3.Value - step_l;
                                    else NT37710_R3.Value = NT37710_R3.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G3.Value = NT37710_G3.Value - step_h;
                                    else NT37710_G3.Value = NT37710_G3.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G3.Value = NT37710_G3.Value - step_l;
                                    else NT37710_G3.Value = NT37710_G3.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B3.Value = NT37710_B3.Value - step_h;
                                    else NT37710_B3.Value = NT37710_B3.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B3.Value = NT37710_B3.Value - step_l;
                                    else NT37710_B3.Value = NT37710_B3.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 21:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R1.Value = NT37710_R1.Value - step_h;
                                    else NT37710_R1.Value = NT37710_R1.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        NT37710_R1.Value = NT37710_R1.Value - step_l;
                                    else NT37710_R1.Value = NT37710_R1.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G1.Value = NT37710_G1.Value - step_h;
                                    else NT37710_G1.Value = NT37710_G1.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        NT37710_G1.Value = NT37710_G1.Value - step_l;
                                    else NT37710_G1.Value = NT37710_G1.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B1.Value = NT37710_B1.Value - step_h;
                                    else NT37710_B1.Value = NT37710_B1.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        NT37710_B1.Value = NT37710_B1.Value - step_l;
                                    else NT37710_B1.Value = NT37710_B1.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                }
                NT37710_GAMMA_Click(NT37710_GammaW_Red, e);
                NT37710_GAMMA_Click(NT37710_GammaW_Green, e);
                NT37710_GAMMA_Click(NT37710_GammaW_Blue, e);
            }
        }



        private void NT37710_Gamma_Load(object sender, EventArgs e)
        {

        }
    }
}
